package com.benny_driving.thread;

import android.os.Handler;
import android.os.Looper;

import com.benny_driving.act.DriInfoAct;
import com.benny_driving.act.DriLstAct;
import com.benny_driving.entity.Form;
import com.benny_driving.http.dao.impl.HttpDaoImpl;

public class CallFormThread extends Thread {
	private static Handler handler = null;
	private Form form;
	private Class<?> context = null;

	public CallFormThread(Form paramForm, Class<?> context) {
		this.form = paramForm;
		this.context = context;
		handler = new Handler();
	}

	public void run() {
		Looper.prepare();
		try {
			String state = HttpDaoImpl.getInstance()
					.sendMatchingForm(this.form);
			if (context == DriInfoAct.class) {
				DriInfoAct.handler.sendMessage(handler.obtainMessage(
						DriInfoAct.RESPHN, state));
			} else {
				DriLstAct.handler.sendMessage(handler.obtainMessage(
						DriLstAct.RESPHN, state));
			}
		} catch (Exception localException) {
			localException.printStackTrace();
			if (context == DriInfoAct.class) {
				DriInfoAct.handler.sendMessage(handler.obtainMessage(
						DriInfoAct.NETWORK_ERROR, "null"));
			} else {
				DriLstAct.handler.sendMessage(handler.obtainMessage(
						DriLstAct.NETWORK_ERROR, "null"));
			}
		} finally {
			Thread.currentThread().interrupt();
		}
	}
}